package com.shujia.day06;

/*
    java中若某一个成员表示多个对象共享的话，可以使用static进行修饰
    1. 被static修饰的成员，称之为类成员，在对象创建之前就存在于方法区中静态区
    2. 被static修饰的成员,可以通过类名直接访问使用,非静态的成员必须要通过对象去调用

 */
public class Person {
    String name;
    private int age;
    static String nationality;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person(String name, int age, String nationality) {
        this.name = name;
        this.age = age;
        this.nationality = nationality;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public void show() {
        System.out.println("姓名：" + name + ", 年龄：" + age + ", 国籍：" + nationality);
    }
}

class PersonDemo{
    public static void main(String[] args) {
        //创建第一个Person对象
        Person p1 = new Person("蔡某某", 18, "中国");
//        Person p2 = new Person("彭于晏", 19);
//        Person p3 = new Person("邓超", 20);
//        Person p4 = new Person("江川", 21);
//
//        p1.show();
//        p2.show();
//        p3.show();
//        p4.show();
        System.out.println(p1.nationality);
        System.out.println(Person.nationality);
//        System.out.println(Person.name);


    }
}
